<?php

/**
 * @package Bike
 * @subpackage Storage
 */

/**
 * List storage class
 * @author Chrome
 * @package Bike
 * @subpackage Storage
 */
class Bike_Storage_List extends Bike_Storage_Base {
	
	/**
	 * Table prefix
	 * @var string
	 */
	protected $prefix = 'lst_';

	/**
	 * @see Bike_Storage_Base::getRecordsByConditions()
	 * @return Traversable
	 */
	public function getRecordsByConditions(array $filters, $offset = 0, $limit = 20, array $sortings = array()){
		parent::getRecordsByConditions($filters, $offset, $limit);
		$filters = $this->readableConnection->makeFilters($filters);
		return $this->readableConnection->fetchData($this->prefix, $this->name, $filters, $offset, $limit, $sortings);
	}

	/* (non-PHPdoc)
	 * @see Bike_Storage_Base::updateRecord()
	 */
	public function updateRecord($id, array $data){
		$data = $this->prepareData($data);
		parent::updateRecord($id, $data);
		return $this->writableConnection->update($this->prefix, $this->name, $id, $data);
	}

	/* (non-PHPdoc)
	 * @see Bike_Storage_Base::insertRecord()
	 */
	public function insertRecord(array $data){
		$data = $this->prepareData($data);
		parent::insertRecord($data);
		return $this->writableConnection->insert($this->prefix, $this->name, $data);
	}

	/* (non-PHPdoc)
	 * @see Bike_Storage_Base::deleteRecord()
	 */
	public function deleteRecord($id){
		parent::deleteRecord($id);
		return $this->writableConnection->delete($this->prefix, $this->name, $id);
	}
}
